/***************************************************************************
 *   Copyright (C) 2008 by Thomas Richards   *
 *   thomi@colon   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <QCoreApplication>
#include <QSettings>
#include <QDebug>

#include "application.h"

int main(int argc, char **argv)
{
	QCoreApplication::setOrganizationName("CppAnalyse");
	QCoreApplication::setOrganizationDomain("CppAnalyse");
	QCoreApplication::setApplicationName("CppAnalyse");
	QSettings::setDefaultFormat(QSettings::IniFormat);
	
	QCoreApplication app(argc, argv);
	Application appObj;
	
	QStringList appArgs = QCoreApplication::arguments();
	if (appArgs.contains("-d"))
	{
		appObj.runDaemon();
	}
	else if ( appArgs.contains("--np"))
	{
		// user wants to make a new project
		int nIndex = appArgs.indexOf("--np");
		
		qDebug () << nIndex << appArgs.count() << appArgs.at(nIndex) << appArgs.at(nIndex + 1);
		if (nIndex < appArgs.count())
		{
			appObj.createProject(appArgs.at(nIndex + 1));
		}
		else
		{
			qFatal("Error - project path not specified.");
			return 1;
		}
		qDebug() << nIndex << appArgs;
		
		return 0;
	}
	else if (appArgs.contains("--rp"))
	{
		// user wants to Run a Project:
		int nIndex = appArgs.indexOf("--rp");
		appObj.runProject(appArgs.at(nIndex + 1));
	}
	else
	{
		appObj.printUsage();
		
		return 0;
	}
	
	QObject::connect(&appObj, SIGNAL(quit()), &app, SLOT(quit()));
	
	return app.exec();
}

